package com.linkturing.swing;

import java.awt.EventQueue;
import java.awt.SystemColor;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;

import com.alibaba.fastjson.JSON;
import com.linkturing.util.Constants;
import com.linkturing.util.JedisUtil;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class WeightingProduct extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;
	private JTextField textField_2;
	private JTextField textField_3;
	private JTextField textField_4;

	JFrame frame = null;
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			@Override
			public void run() {
				try {
					WeightingProduct frame = new WeightingProduct("","","");
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public WeightingProduct(String juanhao,String fenJuanHao,String weight) {
		frame = this;
		//称重
		setTitle("\u79F0\u91CD");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 774, 323);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBounds(0, 0, 238, 41);
		contentPane.add(panel);
		
		JPanel panel_1 = new JPanel();
		panel_1.setBackground(SystemColor.inactiveCaption);
		panel_1.setBounds(0, 51, 958, 239);
		contentPane.add(panel_1);
		panel_1.setLayout(null);

		//卷号
		JLabel lblNewLabel = new JLabel("\u5377\u53F7\uFF1A");
		lblNewLabel.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel.setBounds(60, 10, 47, 31);
		panel_1.add(lblNewLabel);
		
		textField = new JTextField();
		textField.setBounds(117, 10, 98, 37);
		panel_1.add(textField);
		textField.setText(juanhao);
		textField.setColumns(10);

		//分卷号
		JLabel lblNewLabel_1 = new JLabel("\u5206\u5377\u53F7\uFF1A");
		lblNewLabel_1.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel_1.setBounds(250, 10, 57, 31);
		panel_1.add(lblNewLabel_1);
		
		textField_1 = new JTextField();
		textField_1.setColumns(10);
		textField_1.setBounds(317, 10, 98, 37);
		textField_1.setText(fenJuanHao);
		panel_1.add(textField_1);

		//重量(Kg)
		JLabel lblNewLabel_1_1 = new JLabel("\u91CD\u91CF\uFF08kg\uFF09\uFF1A");
		lblNewLabel_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel_1_1.setBounds(452, 10, 93, 31);
		panel_1.add(lblNewLabel_1_1);
		
		textField_2 = new JTextField();
		textField_2.setColumns(10);
		textField_2.setBounds(554, 9, 98, 38);
		textField_2.setText(weight);
		panel_1.add(textField_2);

		//长度(m)
		JLabel lblNewLabel_1_1_1 = new JLabel("\u957F\u5EA6\uFF08m\uFF09\uFF1A");
		lblNewLabel_1_1_1.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel_1_1_1.setBounds(29, 88, 78, 31);
		panel_1.add(lblNewLabel_1_1_1);
		
		textField_3 = new JTextField();
		textField_3.setColumns(10);
		textField_3.setBounds(117, 85, 98, 37);
		panel_1.add(textField_3);
		
		textField_4 = new JTextField();
		textField_4.setColumns(10);
		textField_4.setBounds(317, 82, 98, 40);
		panel_1.add(textField_4);

		//规格
		JLabel lblNewLabel_2 = new JLabel("\u89C4\u683C\uFF1A");
		lblNewLabel_2.setHorizontalAlignment(SwingConstants.RIGHT);
		lblNewLabel_2.setBounds(260, 88, 47, 31);
		panel_1.add(lblNewLabel_2);

		//取消
		JButton btnNewButton_1 = new JButton("\u53D6\u6D88");
		btnNewButton_1.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				frame.dispose();
			}
		});
		btnNewButton_1.setBounds(452, 153, 93, 37);
		panel_1.add(btnNewButton_1);

		//确定
		JButton btnNewButton_1_1 = new JButton("\u786E\u5B9A");
		btnNewButton_1_1.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				String juanhao = textField.getText();
				String fenjuanhao = textField_1.getText();
				String weight = textField_2.getText();
				String length = textField_3.getText();
				String spec = textField_4.getText();
				LtProductQualityBasic pqb = new LtProductQualityBasic();
				pqb.setReelNumber(juanhao);
				pqb.setVolumeNumber(fenjuanhao);
				pqb.setWeight(Integer.parseInt(weight));
				pqb.setLength(Integer.parseInt(length));
				pqb.setSpecs(spec);
				JedisUtil.lpush(Constants.weight+":"+juanhao, JSON.toJSONString(pqb));
				frame.dispose();
				XinhuaApplication.dataTable.reloadTable(Constants.weight+":"+juanhao);

			}
		});
		btnNewButton_1_1.setBounds(280, 153, 93, 37);
		panel_1.add(btnNewButton_1_1);
	}

}
